import { login } from "@/api/user"
import { getToken, setToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken(),
  },
  mutations: {
    setToken(state,token){
      state.token = token
      setToken(token)
    },
    removeToken(state){
      state.token = ''
      removeToken()
    }
  },
  actions: {
    //? 通过接口获取token
    //? commit setToken
    async login({ commit }, data){
      const res = await login(data)
      commit('setToken',res)
    }
  }
}